using System.Drawing;
using Microsoft.Xna.Framework;
using RebelStar.Engine.Sprites;
using Color = Microsoft.Xna.Framework.Graphics.Color;
using Rectangle = Microsoft.Xna.Framework.Rectangle;

namespace RebelStar.Engine.Graphics.GDI
{
    class GDISurface : ISurface
    {
        private System.Drawing.Graphics graphics;

        internal System.Drawing.Graphics Graphics
        {
            get { return graphics; }
            set { graphics = value; }
        }

        public bool BeginDraw()
        {
            return graphics != null;
        }
        public void DrawSprite(SpriteBase sprite, Vector2 position, Rectangle sourceRectangle, Color blendColor, float scale)
        {
            if (graphics == null) return;

            RectangleF destRect = new RectangleF(
                position.X, position.Y,
                sourceRectangle.Width*scale, sourceRectangle.Height*scale);
            RectangleF srcRect = new RectangleF(
                sourceRectangle.X, sourceRectangle.Y,
                sourceRectangle.Width, sourceRectangle.Height);
            graphics.DrawImage(sprite.Image, destRect, srcRect, GraphicsUnit.Pixel);
        }
        public void EndDraw()
        {
            this.Graphics = null;
        }

        public void Copy(ISurface source)
        {
            GDIBuffer src = source as GDIBuffer;
            if (src!=null)
                graphics.DrawImage(src.Image, 0,0);

        }

        public void Clear(System.Drawing.Color color)
        {
            if (graphics != null) graphics.Clear(color);
        }
    }
}
